<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户编辑</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/select.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.idTabs.min.js"></script>
<script type="text/javascript" src="js/select-ui.min.js"></script>

</head>

<body>
	<!-- 隐藏域 -->
	<input type="hidden" class="userCode" />
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="index.html">首页</a></li>
    <li><a href="user_list.html" target="rightFrame">用户管理</a></li>
    <li><a href="#" id="text"></a></li>
    </ul>
    </div>
    
    <div class="formbody">
    
    <div class="formtitle"><span>基本信息</span></div>
    
    <ul class="forminfo">
    <li><label>用户名<b>*</b></label><input type="text" class="dfinput userName" /><i>用户名字母加数字组合，不少于6位</i></li>
    <li><label>密码<b>*</b></label><input  type="password" class="dfinput passWord" /><i>密码不能出现空格，且不能少于6位</i></li>
	<li><label>角色<b>*</b></label><cite><input name="roleName" type="radio" value="管理员" checked="checked" />管理员&nbsp;&nbsp;&nbsp;&nbsp;<input name="roleName" type="radio" value="操作员" />操作员</cite></li>
    <li><label>备注</label><textarea class="textinput remark"></textarea></li>
    <li><label>&nbsp;</label><input  type="button" class="btn" value="提交"/></li>
    </ul>
    
    </div>
    
    <div class="tip">
    	<div class="tiptop"><span>提示信息</span><a></a></div>
        
      <div class="tipinfo">
        <span><img src="images/ticon.png" /></span>
        <div class="tipright">
        <p>是否确认提交信息 ？</p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite>
        </div>
        </div>
        
        <div class="tipbtn">
        <input name="" type="button"  class="sure" value="确定" />&nbsp;
        <input name="" type="button"  class="cancel" value="取消" />
        </div>
    
    </div>  
  <script type="text/javascript">

$(document).ready(function(e) {
	var hid=location.search.substring(5);
	var title="添加";
	if(hid!=null&&hid!=""){
		title="修改";
		var jsonstr={"id":hid};
		$.ajax({
			url:"/Servicing/user/findUserById",
			data:jsonstr,
			dataType:"json",
			type:"POST",
			success:function(result){
				console.log(result);
				$.each(result,function(key,value){
					$('.userCode').val(value.userCode);					
					$('.userName').val(value.userName);
					$('.passWord').val(value.passWord);
					$("input[name='roleName'][value="+value.roleName+"]").attr("checked",true); 
					$('.remark').val(value.remark);
				})
			}
		})
	}
	$('#text').text(title);
    $(".select").uedSelect({
		width : 167		  
	});
	 
	$(".btn").click(function(){
		$(".tip").fadeIn(200);
	});
	 $(".tiptop a").click(function(){
		$(".tip").fadeOut(200);
	});


	 $(".sure").click(function(){			
		 //确认回调
		if(hid!=null&&hid!=""){
			 var code=$('.userCode').val();
			 var name=$('.userName').val();
			 var pwd=$('.passWord').val();
			 var role=$("input[name='roleName']:checked").val();
			 var remark=$('.remark').val();
			 var jsonStr1={"userCode":code,"userName":name,"passWord":pwd,
					 "roleName":role,"remark":remark};
			 $.ajax({
				 url:"/Servicing/user/updateUser",
				 data:jsonStr1,
				 dataType:"text",
				 type:"POST",
				 success:function(result){
					 if(result="success"){
						 alert("用户修改成功！");
						 $(".tip").fadeOut(100);
					 }else{
						 alert("用户修改失败！");
						 $(".tip").fadeOut(100);
					 }
				 }
			 })
		}else{
			 var code="U"+getTime();
			 var name=$('.userName').val();
			 var pwd=$('.passWord').val();
			 var role=$("input[name='roleName']:checked").val();
			 var remark=$('.remark').val();
			 var jsonStr2={"userCode":code,"userName":name,"passWord":pwd,
					 "roleName":role,"remark":remark};
			 $.ajax({
				 url:"/Servicing/user/addUser",
				 data:jsonStr2,
				 dataType:"text",
				 type:"POST",
				 success:function(result){
					 if(result="success"){
						 alert("添加成功！");
						 $(".tip").fadeOut(100);
					 }else{
						 alert("添加失败！");
						 $(".tip").fadeOut(100);
					 }
				 }
			 })
		}

	
		 
	});
	//关闭提示信息
	$(".cancel").click(function(){
		  $(".tip").fadeOut(100);
	});
});

//获取当前系统时间 
function getTime(){
    var mydate = new Date();
    var str = mydate.getHours();
    str+=mydate.getMinutes() ;
    str+=mydate.getSeconds() ;
    return str; 
}
</script> 	
</body>
</html>
